
<!DOCTYPE html>
<html lang="zh-CN" class="loading">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>移动端人物渲染 - 浪子之心</title>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="google" content="notranslate" />
    <meta name="keywords" content="Blog,"> 
    <meta name="description" content="MrChen Bolg,
模型与贴图分析模型导入武器时属于泛型。
psk导入模型时3dmax效果比blender好，blender的模型不会平滑，选用3dmax加载模型。
贴图分析Albedo 贴图包含金属非金属部分的基本,"> 
    <meta name="author" content="Jack Chen"> 
    <link rel="alternative" href="atom.xml" title="浪子之心" type="application/atom+xml"> 
    <link rel="icon" href="/blog/img/favicon.png"> 
    
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">

    
<link rel="stylesheet" href="/blog/css/diaspora.css">

<meta name="generator" content="Hexo 5.4.1"><link rel="stylesheet" href="/blog/css/prism.css" type="text/css"></head>

<body class="loading">
    <span id="config-title" style="display:none">浪子之心</span>
    <div id="loader"></div>
    <div id="single">
    <div id="top" style="display: block;">
    <div class="bar" style="width: 0;"></div>
    <a class="iconfont icon-home image-icon" href="javascript:;" data-url="https://mrchenlearnspace.github.io/blog"></a>
    <div title="播放/暂停" class="iconfont icon-play"></div>
    <h3 class="subtitle">移动端人物渲染</h3>
    <div class="social">
        <div>
            <div class="share">
                <a title="获取二维码" class="iconfont icon-scan" href="javascript:;"></a>
            </div>
            <div id="qr"></div>
        </div>
    </div>
    <div class="scrollbar"></div>
</div>

    <div class="section">
        <div class="article">
    <div class='main'>
        <h1 class="title">移动端人物渲染</h1>
        <div class="stuff">
            <span>四月 14, 2022</span>
            
  <ul class="post-tags-list" itemprop="keywords"><li class="post-tags-list-item"><a class="post-tags-list-link" href="/blog/tags/Shader/" rel="tag">Shader</a></li></ul>


        </div>
        <div class="content markdown">
            <p><img src="https://img-blog.csdnimg.cn/c4b325b53d024b859f7199f85712707f.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAUEMgRXJyb3I=,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<h1 id="模型与贴图分析"><a href="#模型与贴图分析" class="headerlink" title="模型与贴图分析"></a>模型与贴图分析</h1><h2 id="模型"><a href="#模型" class="headerlink" title="模型"></a>模型</h2><p>导入武器时属于泛型。</p>
<p>psk导入模型时3dmax效果比blender好，blender的模型不会平滑，选用3dmax加载模型。</p>
<h2 id="贴图分析"><a href="#贴图分析" class="headerlink" title="贴图分析"></a>贴图分析</h2><h3 id="Albedo-贴图"><a href="#Albedo-贴图" class="headerlink" title="Albedo 贴图"></a>Albedo 贴图</h3><p>包含金属非金属部分的基本颜色</p>
<h3 id="combmap-贴图"><a href="#combmap-贴图" class="headerlink" title="combmap 贴图"></a>combmap 贴图</h3><p>R通道是roughness 粗糙度</p>
<p>G通道是金属度</p>
<p>B，如果皮肤通道为红色部分地方为蓝色就是皮肤部分</p>
<h3 id="法线贴图"><a href="#法线贴图" class="headerlink" title="法线贴图"></a>法线贴图</h3><p>见之前文章</p>
<h1 id="光照框架"><a href="#光照框架" class="headerlink" title="光照框架"></a>光照框架</h1><h2 id="直接光照反射"><a href="#直接光照反射" class="headerlink" title="直接光照反射"></a>直接光照反射</h2><h3 id="lambert"><a href="#lambert" class="headerlink" title="lambert"></a>lambert</h3><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">half half_lambert = (diffuse_term+<span class="number">1.0</span>)*<span class="number">0.5</span>;</span><br></pre></td></tr></table></figure>

<h3 id="SSS-散光"><a href="#SSS-散光" class="headerlink" title="SSS 散光"></a>SSS 散光</h3><p><img src="https://img-blog.csdnimg.cn/5a277f97ec634e89b0a8a50794534582.png" alt="请添加图片描述"></p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">half skin_area  = <span class="number">1</span>- comb_map.b;<span class="comment">//获取颜色部分</span></span><br><span class="line">half2 uv_lut = <span class="built_in">float2</span>(<span class="built_in">min</span>(<span class="number">1</span>, diffuse_term*atten  +_LUTOffset),_CurveOffset);<span class="comment">//将颜色分布在光照边缘</span></span><br><span class="line">half3 lut_color = <span class="built_in">tex2D</span>(_SSSTrick,uv_lut);</span><br><span class="line">half3 sss_diffuse = lut_color *base_col*_LightColor0.xyz* half_lambert;<span class="comment">//散射部分光照</span></span><br><span class="line">half3 diffuse = <span class="built_in">lerp</span>(comm_diffuse,sss_diffuse,skin_area);<span class="comment">//区分皮肤和非皮肤部分</span></span><br></pre></td></tr></table></figure>

<h2 id="直接光镜面反射"><a href="#直接光镜面反射" class="headerlink" title="直接光镜面反射"></a>直接光镜面反射</h2><h3 id="Blin-Phong"><a href="#Blin-Phong" class="headerlink" title="Blin-Phong"></a>Blin-Phong</h3><p>利用V+L代替reflect(-L,N)</p>
<h3 id="KK各项异性"><a href="#KK各项异性" class="headerlink" title="KK各项异性"></a>KK各项异性</h3><p> 光照射头发、不锈钢锅底，光碟会出现这样的现象。头发可以去除间接光的漫反射。</p>
<p><strong>简单原理版</strong></p>
<p><img src="https://img-blog.csdnimg.cn/274730248572485cb0c99a614a6ff9e7.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAUEMgRXJyb3I=,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p><img src="https://img-blog.csdnimg.cn/d25cb401a6fe4aff9336ce2fa3dc51e3.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAUEMgRXJyb3I=,size_16,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">half3 half_dir =<span class="built_in">normalize</span>( light_dir+view_dir);<span class="comment">//得到半角向量</span></span><br><span class="line">           half2 uv_shift = i.texcoord * _ShiftNoise_ST.xy+_ShiftNoise_ST.zw;<span class="comment">//控制发丝密度</span></span><br><span class="line">           half shiftnoise = <span class="built_in">tex2D</span>(_ShiftNoise,uv_shift).r;</span><br><span class="line">           shiftnoise =(shiftnoise*<span class="number">2.0</span><span class="number">-1.0</span>)*_NoiseIntensity;<span class="comment">//从-1 - 1 映射到 0 - 1</span></span><br><span class="line">           half3 b_offset =    normal_dir*(_Shiftoffset+shiftnoise);<span class="comment">//法线方向偏移（上下移动）</span></span><br><span class="line">          </span><br><span class="line">           binormal_dir = <span class="built_in">normalize</span>(binormal_dir+ b_offset);</span><br><span class="line">           half TdotN=<span class="built_in">dot</span>(binormal_dir,half_dir);</span><br><span class="line">           half sinTH = <span class="built_in">sqrt</span>(<span class="number">1</span>-TdotN*TdotN);</span><br><span class="line">           fixed3 specular_color = <span class="built_in">pow</span>(<span class="built_in">max</span>(<span class="number">0</span>,sinTH),_Shininess)<span class="comment">//将公式</span></span><br><span class="line">           *_LightColor0.xyz;</span><br></pre></td></tr></table></figure>

<p><img src="https://o.130014.xyz/2022/04/14/_ShiftTexture.png" alt="ShiftNoises"></p>
<p>​                                                                                        <strong>_ShiftNoise</strong></p>
<p>头发部分体现,调了半天没调好，开摆。</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">half roughness = <span class="number">0.2</span>;</span><br><span class="line">         half3 half_dir =<span class="built_in">normalize</span>( light_dir+view_dir);</span><br><span class="line">         half2 uv_Anoise = i.texcoord*_AnoiseMap_ST.xy+_AnoiseMap_ST.zw;</span><br><span class="line">         half3 aniso_noise = <span class="built_in">tex2D</span>(_AnoiseMap,uv_Anoise);</span><br><span class="line"></span><br><span class="line">         half NdotH = <span class="built_in">dot</span>(normal_dir,half_dir);</span><br><span class="line">         half TdotH = <span class="built_in">dot</span>(tangent_dir,half_dir);</span><br><span class="line"></span><br><span class="line">         half NdotV = <span class="built_in">max</span>(<span class="number">0</span>, <span class="built_in">dot</span>(normal_dir,view_dir));</span><br><span class="line">         half aniso_atten = <span class="built_in">saturate</span>(<span class="built_in">sqrt</span>(<span class="built_in">max</span>(<span class="number">0</span>,half_lambert/NdotV)))*atten;</span><br><span class="line">         <span class="comment">//spec1</span></span><br><span class="line">         half3 specular_color1 = _SpecularColor1 + base_col;</span><br><span class="line">         half3 aniso_offset1 = normal_dir *(aniso_noise*_SpecNoise1+_Shiftoffset1);</span><br><span class="line">         half3 binormal_dir1 = <span class="built_in">normalize</span>(binormal_dir + aniso_offset1);</span><br><span class="line">         half BdotH1 = <span class="built_in">dot</span>(binormal_dir1,half_dir)/ _SpecShininess1;</span><br><span class="line">         half3 specular_term1 = <span class="built_in">exp</span>(-(TdotH*TdotH+BdotH1*BdotH1)/(<span class="number">1.0</span>+NdotH));</span><br><span class="line">         half3 specular1 = specular_term1*aniso_atten*specular_color1*_LightColor0.xyz;</span><br><span class="line">         </span><br><span class="line">         half3 specular_color2 = _SpecularColor2 + base_col;</span><br><span class="line">         half3 aniso_offset2 = normal_dir *(aniso_noise*_SpecNoise2+_Shiftoffset2);</span><br><span class="line">         half3 binormal_dir2 = <span class="built_in">normalize</span>(binormal_dir + aniso_offset2);</span><br><span class="line">         half BdotH2 = <span class="built_in">dot</span>(binormal_dir2,half_dir)/ _SpecShininess2;</span><br><span class="line">         half3 specular_term2 = <span class="built_in">exp</span>(-(TdotH*TdotH+BdotH2*BdotH2)/(<span class="number">1.0</span>+NdotH));</span><br><span class="line">         half3 specular2 = specular_term2*aniso_atten*specular_color2*_LightColor0.xyz;</span><br><span class="line">         half3 specular = specular1+specular2;</span><br><span class="line">         col.xyz+=specular;</span><br></pre></td></tr></table></figure>

<h1 id="ACES-Tonemapping"><a href="#ACES-Tonemapping" class="headerlink" title="ACES_Tonemapping"></a>ACES_Tonemapping</h1><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="function">float3 <span class="title">ACES_Tonemapping</span><span class="params">(float3 x)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="type">float</span> a = <span class="number">2.51f</span>;</span><br><span class="line">  <span class="type">float</span> b = <span class="number">0.03f</span>;</span><br><span class="line">  <span class="type">float</span> c = <span class="number">2.43f</span>;</span><br><span class="line">  <span class="type">float</span> d = <span class="number">0.59f</span>;</span><br><span class="line">  <span class="type">float</span> e = <span class="number">0.14f</span>;</span><br><span class="line">  float3 encode_color = <span class="built_in">saturate</span>((x*(a*x + b)) / (x*(c*x + d) + e));</span><br><span class="line">  <span class="keyword">return</span> encode_color;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h1 id="宏开关"><a href="#宏开关" class="headerlink" title="宏开关"></a>宏开关</h1><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//Properties</span></span><br><span class="line">[<span class="built_in">Toggle</span>(_D_ok)] _DiffuseCheck(<span class="string">&quot;_DiffuseCheck&quot;</span>,Float) = <span class="number">1.0</span></span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line"><span class="comment">//Pass</span></span><br><span class="line"><span class="meta">#<span class="keyword">pragma</span> shader_feature _D_ok;</span></span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> _D_ok</span></span><br><span class="line">    one</span><br><span class="line"><span class="meta">#<span class="keyword">else</span></span></span><br><span class="line">    two</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>或者把</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">pragma</span> shader_feature _D_ok;</span></span><br></pre></td></tr></table></figure>

<p>换成</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">pragma</span> multi_compile _D_ok;</span></span><br></pre></td></tr></table></figure>

<h1 id="人物代码"><a href="#人物代码" class="headerlink" title="人物代码"></a>人物代码</h1><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br></pre></td><td class="code"><pre><span class="line">Shader <span class="string">&quot;Human&quot;</span></span><br><span class="line">&#123;</span><br><span class="line">    Properties</span><br><span class="line">    &#123;</span><br><span class="line">        _Diffuse(<span class="string">&quot;Diffuse&quot;</span>, <span class="number">2</span>D) = <span class="string">&quot;white&quot;</span> &#123;&#125;</span><br><span class="line">        _Normal(<span class="string">&quot;Normal&quot;</span>, <span class="number">2</span>D) = <span class="string">&quot;bump&quot;</span> &#123;&#125;</span><br><span class="line">        _NormalIntensity(<span class="string">&quot;Normal Intensity&quot;</span>, Float) = <span class="number">1.0</span></span><br><span class="line">        _Combmap(<span class="string">&quot;Combmap&quot;</span>, <span class="number">2</span>D) = <span class="string">&quot;black&quot;</span> &#123;&#125;</span><br><span class="line">        _SSSTrick(<span class="string">&quot;SSSTrick&quot;</span>, <span class="number">2</span>D) = <span class="string">&quot;black&quot;</span> &#123;&#125;</span><br><span class="line">        _CurveOffset(<span class="string">&quot;Curve Offset&quot;</span>, <span class="built_in">Range</span>(<span class="number">-1</span>,<span class="number">1</span>)) = <span class="number">1.0</span></span><br><span class="line">        _LUTOffset(<span class="string">&quot;LUT Offset&quot;</span>, <span class="built_in">Range</span>(<span class="number">-1</span>,<span class="number">1</span>)) = <span class="number">1.0</span></span><br><span class="line">        _SpecShininess(<span class="string">&quot;Spec Shininess&quot;</span>, Float) = <span class="number">1.0</span></span><br><span class="line"></span><br><span class="line">        _EnvMap(<span class="string">&quot;EnvMap&quot;</span>, Cube) = <span class="string">&quot;black&quot;</span> &#123;&#125;</span><br><span class="line">        _Expose(<span class="string">&quot;Expose&quot;</span>, Float) = <span class="number">1.0</span></span><br><span class="line"></span><br><span class="line">        [HideInInspector]<span class="built_in">custom_SHAr</span>(<span class="string">&quot;Custom SHAr&quot;</span>, Vector) = (<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>)</span><br><span class="line">        [HideInInspector]<span class="built_in">custom_SHAg</span>(<span class="string">&quot;Custom SHAg&quot;</span>, Vector) = (<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>)</span><br><span class="line">        [HideInInspector]<span class="built_in">custom_SHAb</span>(<span class="string">&quot;Custom SHAb&quot;</span>, Vector) = (<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>)</span><br><span class="line">        [HideInInspector]<span class="built_in">custom_SHBr</span>(<span class="string">&quot;Custom SHBr&quot;</span>, Vector) = (<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>)</span><br><span class="line">        [HideInInspector]<span class="built_in">custom_SHBg</span>(<span class="string">&quot;Custom SHBg&quot;</span>, Vector) = (<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>)</span><br><span class="line">        [HideInInspector]<span class="built_in">custom_SHBb</span>(<span class="string">&quot;Custom SHBb&quot;</span>, Vector) = (<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>)</span><br><span class="line">        [HideInInspector]<span class="built_in">custom_SHC</span>(<span class="string">&quot;Custom SHC&quot;</span>, Vector) = (<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>)</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">    SubShader</span><br><span class="line">    &#123;</span><br><span class="line">        Tags &#123; <span class="string">&quot;RenderType&quot;</span>=<span class="string">&quot;Opaque&quot;</span> &#125;</span><br><span class="line">        LOD <span class="number">100</span></span><br><span class="line"></span><br><span class="line">        Pass</span><br><span class="line">        &#123;</span><br><span class="line">           Tags &#123; <span class="string">&quot;LightMode&quot;</span> = <span class="string">&quot;ForwardBase&quot;</span> &#125;</span><br><span class="line">            CGPROGRAM</span><br><span class="line">            <span class="meta">#<span class="keyword">pragma</span> vertex vert</span></span><br><span class="line">            <span class="meta">#<span class="keyword">pragma</span> fragment frag</span></span><br><span class="line">            <span class="meta">#<span class="keyword">pragma</span> multi_compile_fwdbase</span></span><br><span class="line">            <span class="meta">#<span class="keyword">include</span> <span class="string">&quot;AutoLight.cginc&quot;</span></span></span><br><span class="line">            <span class="meta">#<span class="keyword">include</span> <span class="string">&quot;UnityCG.cginc&quot;</span></span></span><br><span class="line">            <span class="keyword">struct</span> appdata</span><br><span class="line">            &#123;</span><br><span class="line">                float4 vertex : POSITION;</span><br><span class="line">                float2 uv : TEXCOORD0;</span><br><span class="line">                float3 normal:NORMAL;</span><br><span class="line">                float4 tangent:TANGENT;</span><br><span class="line">            &#125;;</span><br><span class="line">            <span class="keyword">struct</span> <span class="title class_">v2f</span></span><br><span class="line">            &#123;</span><br><span class="line">                float2 texcoord : TEXCOORD0;</span><br><span class="line">                </span><br><span class="line">                float4 pos : SV_POSITION;</span><br><span class="line">                float3 normal_world:TEXCOORD1;</span><br><span class="line">                float3 binormal_world:TEXCOORD2;</span><br><span class="line">                float3 tangent_world:TEXCOORD3;</span><br><span class="line">                float3 pos_world:TEXCOORD4;</span><br><span class="line">                <span class="built_in">LIGHTING_COORDS</span>(<span class="number">5</span>,<span class="number">6</span>)</span><br><span class="line">            &#125;;</span><br><span class="line">            sampler2D _Diffuse;</span><br><span class="line">            float4 _Diffuse_ST;</span><br><span class="line">            sampler2D _Normal;</span><br><span class="line">            <span class="type">float</span> _NormalIntensity;</span><br><span class="line">            <span class="type">float</span> _SpecShininess;</span><br><span class="line">            <span class="type">float</span> _Expose;</span><br><span class="line">            float4 _LightColor0;</span><br><span class="line">            sampler2D _Combmap;</span><br><span class="line">            sampler2D _SSSTrick;</span><br><span class="line">            </span><br><span class="line">            samplerCUBE _EnvMap;</span><br><span class="line">            float4 _EnvMap_HDR;</span><br><span class="line">            <span class="type">float</span> _CurveOffset;</span><br><span class="line">            <span class="type">float</span> _LUTOffset;</span><br><span class="line">            </span><br><span class="line">            float4 custom_SHAr;</span><br><span class="line">            float4 custom_SHAg;</span><br><span class="line">            float4 custom_SHAb;</span><br><span class="line">            float4 custom_SHBr;</span><br><span class="line">            float4 custom_SHBg;</span><br><span class="line">            float4 custom_SHBb;</span><br><span class="line">            float4 custom_SHC;</span><br><span class="line">            <span class="function">float3 <span class="title">SH</span><span class="params">(half3 normal_dir)</span></span></span><br><span class="line"><span class="function">            </span>&#123;</span><br><span class="line">                float4 normalForSH = <span class="built_in">float4</span>(normal_dir, <span class="number">1.0</span>);</span><br><span class="line">                <span class="comment">//SHEvalLinearL0L1</span></span><br><span class="line">                half3 x;</span><br><span class="line">                x.r = <span class="built_in">dot</span>(custom_SHAr, normalForSH);</span><br><span class="line">                x.g = <span class="built_in">dot</span>(custom_SHAg, normalForSH);</span><br><span class="line">                x.b = <span class="built_in">dot</span>(custom_SHAb, normalForSH);</span><br><span class="line">                <span class="comment">//SHEvalLinearL2</span></span><br><span class="line">                half3 x1, x2;</span><br><span class="line">                <span class="comment">// 4 of the quadratic (L2) polynomials</span></span><br><span class="line">                half4 vB = normalForSH.xyzz * normalForSH.yzzx;</span><br><span class="line">                x1.r = <span class="built_in">dot</span>(custom_SHBr, vB);</span><br><span class="line">                x1.g = <span class="built_in">dot</span>(custom_SHBg, vB);</span><br><span class="line">                x1.b = <span class="built_in">dot</span>(custom_SHBb, vB);</span><br><span class="line">                <span class="comment">// Final (5th) quadratic (L2) polynomial</span></span><br><span class="line">                half vC = normalForSH.x*normalForSH.x - normalForSH.y*normalForSH.y;</span><br><span class="line">                x2 = custom_SHC.rgb * vC;</span><br><span class="line">                float3 sh = <span class="built_in">max</span>(<span class="built_in">float3</span>(<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>), (x + x1 + x2));</span><br><span class="line">                sh = <span class="built_in">pow</span>(sh, <span class="number">1.0</span> / <span class="number">2.2</span>);</span><br><span class="line">                <span class="keyword">return</span> sh;</span><br><span class="line">            &#125;</span><br><span class="line">             <span class="function">v2f <span class="title">vert</span> <span class="params">(appdata v)</span></span></span><br><span class="line"><span class="function">            </span>&#123;</span><br><span class="line">                v2f o;</span><br><span class="line">                o.pos = <span class="built_in">UnityObjectToClipPos</span>(v.vertex);</span><br><span class="line">                o.texcoord =v.uv;</span><br><span class="line">                o.normal_world = <span class="built_in">normalize</span>(<span class="built_in">mul</span>(<span class="built_in">float4</span>(v.normal,<span class="number">0.0</span>),unity_WorldToObject)).xyz;</span><br><span class="line">                o.tangent_world = <span class="built_in">normalize</span>(<span class="built_in">mul</span>(unity_ObjectToWorld,<span class="built_in">float4</span>(v.tangent.xyz,<span class="number">0.0</span>)));</span><br><span class="line">                o.pos_world = <span class="built_in">normalize</span>(<span class="built_in">mul</span>(unity_ObjectToWorld,<span class="built_in">float4</span>(v.vertex.xyz,<span class="number">0.0</span>)));</span><br><span class="line">                o.binormal_world =<span class="built_in">normalize</span>(<span class="built_in">cross</span>(o.normal_world,o.tangent_world)*v.tangent.w);</span><br><span class="line">                <span class="built_in">TRANSFER_VERTEX_TO_FRAGMENT</span>(o);</span><br><span class="line">                <span class="keyword">return</span> o;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="function">fixed4 <span class="title">frag</span> <span class="params">(v2f i)</span> : SV_Target</span></span><br><span class="line"><span class="function">            &#123;</span></span><br><span class="line">                half atten = <span class="built_in">LIGHT_ATTENUATION</span> (i);</span><br><span class="line">                fixed4 col = <span class="built_in">fixed4</span>(<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>);</span><br><span class="line">                fixed3 albedo = <span class="built_in">tex2D</span>(_Diffuse, i.texcoord).xyz;</span><br><span class="line">                fixed3 comb_map = <span class="built_in">tex2D</span>(_Combmap, i.texcoord).xyz;</span><br><span class="line">                </span><br><span class="line">                half metal = comb_map.g;</span><br><span class="line">                fixed3 base_col =albedo * (<span class="number">1</span>-metal);</span><br><span class="line">                fixed3 spec_color = <span class="built_in">lerp</span>(<span class="number">0.04</span>,albedo,metal);</span><br><span class="line"></span><br><span class="line">                half3 normal_dir    = <span class="built_in">normalize</span>(i.normal_world);</span><br><span class="line">                half3 pos_world    = <span class="built_in">normalize</span>(i.pos_world);</span><br><span class="line">                half3 tangent_dir   = <span class="built_in">normalize</span>(i.tangent_world)*_NormalIntensity;</span><br><span class="line">                half3 binormal_dir  = <span class="built_in">normalize</span>(i.binormal_world)*_NormalIntensity;</span><br><span class="line">                half4 normalmap= <span class="built_in">tex2D</span>(_Normal,i.texcoord);</span><br><span class="line">                half3 normal_data = <span class="built_in">UnpackNormal</span>( normalmap);</span><br><span class="line">                float3x3 TBN = <span class="built_in">float3x3</span>(tangent_dir,binormal_dir,normal_dir);</span><br><span class="line">                normal_dir = <span class="built_in">normalize</span>(<span class="built_in">mul</span>(normal_data,TBN));</span><br><span class="line"></span><br><span class="line">                half3 view_dir = <span class="built_in">normalize</span>(_WorldSpaceCameraPos.xyz-pos_world);</span><br><span class="line">                half3 light_dir = <span class="built_in">normalize</span>(_WorldSpaceLightPos0.xyz);</span><br><span class="line">                </span><br><span class="line">                <span class="comment">//直接光漫反射</span></span><br><span class="line"></span><br><span class="line">                half diffuse_term = <span class="built_in">max</span>(<span class="built_in">dot</span>(normal_dir,light_dir),<span class="number">0</span>);</span><br><span class="line">                half3 comm_diffuse = diffuse_term*base_col*atten*_LightColor0.xyz;</span><br><span class="line">                half half_lambert = (diffuse_term+<span class="number">1.0</span>)*<span class="number">0.5</span>;</span><br><span class="line">                half skin_area  = <span class="number">1</span>- comb_map.b;</span><br><span class="line">                half2 uv_lut = <span class="built_in">float2</span>(<span class="built_in">min</span>(<span class="number">1</span>, diffuse_term*atten  +_LUTOffset),_CurveOffset);</span><br><span class="line">                half3 lut_color = <span class="built_in">tex2D</span>(_SSSTrick,uv_lut);</span><br><span class="line">                half3 sss_diffuse = lut_color *base_col*_LightColor0.xyz* half_lambert;</span><br><span class="line">                half3 diffuse = <span class="built_in">lerp</span>(comm_diffuse,sss_diffuse,skin_area);</span><br><span class="line">                col.xyz+=diffuse;</span><br><span class="line">              <span class="comment">//直接光镜面反射</span></span><br><span class="line">               half3 half_dir =<span class="built_in">normalize</span>( light_dir+view_dir);</span><br><span class="line">               half roughness = comb_map.r;</span><br><span class="line">               half smoothness = <span class="number">1.0</span>-roughness;</span><br><span class="line">               half shininess = <span class="built_in">lerp</span>(<span class="number">1.0</span>,_SpecShininess,smoothness);</span><br><span class="line">               half reflect_term = <span class="built_in">pow</span>(<span class="built_in">max</span>(<span class="number">0</span>,<span class="built_in">dot</span>(normal_dir,half_dir)),shininess);</span><br><span class="line">               half3 specular = reflect_term *  spec_color*atten*_LightColor0.xyz;</span><br><span class="line">               col.xyz+=specular;</span><br><span class="line">               <span class="comment">//间接光照</span></span><br><span class="line">               </span><br><span class="line">               half3 env_diffuse = <span class="built_in">SH</span>(normal_dir)*base_col*half_lambert; </span><br><span class="line">               <span class="comment">// sample the texture</span></span><br><span class="line">               col.xyz+=env_diffuse;</span><br><span class="line"></span><br><span class="line">                <span class="comment">//间接镜面反射</span></span><br><span class="line">               roughness=roughness*(<span class="number">1.7</span><span class="number">-0.7</span>*roughness);</span><br><span class="line">               half mip_level = roughness*<span class="number">6.0</span>;</span><br><span class="line">               half4 Cube_col=<span class="built_in">texCUBElod</span>(_EnvMap,<span class="built_in">float4</span>(half_dir,mip_level));</span><br><span class="line">               half3 EnvHDR_col=<span class="built_in">DecodeHDR</span>(Cube_col,_EnvMap_HDR);</span><br><span class="line">               half3 env_specular = EnvHDR_col *spec_color*half_lambert*_Expose;</span><br><span class="line">               col.xyz+=env_specular;</span><br><span class="line">               col.xyz*=<span class="number">0.8</span>;</span><br><span class="line">               <span class="keyword">return</span> col;</span><br><span class="line">              <span class="comment">// return fixed4(diffuse,1.0);</span></span><br><span class="line">            &#125;</span><br><span class="line">            ENDCG</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    FallBack <span class="string">&quot;Diffuse&quot;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="头发代码"><a href="#头发代码" class="headerlink" title="头发代码"></a>头发代码</h1><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br></pre></td><td class="code"><pre><span class="line">Shader <span class="string">&quot;Hair&quot;</span></span><br><span class="line">&#123;</span><br><span class="line">    Properties</span><br><span class="line">    &#123;</span><br><span class="line">        _Diffuse(<span class="string">&quot;Diffuse&quot;</span>, <span class="number">2</span>D) = <span class="string">&quot;white&quot;</span> &#123;&#125;</span><br><span class="line">        _DiffuseColor(<span class="string">&quot;Diffuse Color&quot;</span>, Color) = (<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>)</span><br><span class="line">        _Normal(<span class="string">&quot;Normal&quot;</span>, <span class="number">2</span>D) = <span class="string">&quot;bump&quot;</span> &#123;&#125;</span><br><span class="line">        _NormalIntensity(<span class="string">&quot;Normal Intensity&quot;</span>, Float) = <span class="number">1.0</span></span><br><span class="line"></span><br><span class="line">        _AnoiseMap(<span class="string">&quot;AnoiseMap&quot;</span>, <span class="number">2</span>D) = <span class="string">&quot;gray&quot;</span> &#123;&#125;</span><br><span class="line">        _SpecularColor1(<span class="string">&quot;Specular Color1&quot;</span>, Color) = (<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>)</span><br><span class="line">        _SpecShininess1(<span class="string">&quot;Spec Shininess1&quot;</span>, Float) = <span class="number">1.0</span></span><br><span class="line">        _Shiftoffset1 (<span class="string">&quot;Shift offset1&quot;</span>, <span class="built_in">Range</span>(<span class="number">-10</span>,<span class="number">10</span>)) = <span class="number">1.0</span></span><br><span class="line">        _SpecNoise1 (<span class="string">&quot;Spec Noise1&quot;</span>, Float) = <span class="number">1.0</span></span><br><span class="line"></span><br><span class="line">        _SpecularColor2(<span class="string">&quot;Specular Color2&quot;</span>, Color) = (<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>)</span><br><span class="line">        _SpecShininess2(<span class="string">&quot;Spec Shininess2&quot;</span>, Float) = <span class="number">1.0</span></span><br><span class="line">        _Shiftoffset2 (<span class="string">&quot;Shift offset2&quot;</span>, <span class="built_in">Range</span>(<span class="number">-10</span>,<span class="number">10</span>)) = <span class="number">1.0</span></span><br><span class="line">        _SpecNoise2 (<span class="string">&quot;Spec Noise2&quot;</span>, Float) = <span class="number">1.0</span></span><br><span class="line"></span><br><span class="line">        _EnvMap(<span class="string">&quot;EnvMap&quot;</span>, Cube) = <span class="string">&quot;black&quot;</span> &#123;&#125;</span><br><span class="line">        _Expose(<span class="string">&quot;Expose&quot;</span>, Float) = <span class="number">1.0</span></span><br><span class="line">    &#125;</span><br><span class="line">    SubShader</span><br><span class="line">    &#123;</span><br><span class="line">        Tags &#123; <span class="string">&quot;RenderType&quot;</span>=<span class="string">&quot;Opaque&quot;</span> &#125;</span><br><span class="line">        LOD <span class="number">100</span></span><br><span class="line"></span><br><span class="line">        Pass</span><br><span class="line">        &#123;</span><br><span class="line">           Tags &#123; <span class="string">&quot;LightMode&quot;</span> = <span class="string">&quot;ForwardBase&quot;</span> &#125;</span><br><span class="line">            CGPROGRAM</span><br><span class="line">            <span class="meta">#<span class="keyword">pragma</span> vertex vert</span></span><br><span class="line">            <span class="meta">#<span class="keyword">pragma</span> fragment frag</span></span><br><span class="line">            <span class="meta">#<span class="keyword">pragma</span> multi_compile_fwdbase</span></span><br><span class="line">            <span class="meta">#<span class="keyword">include</span> <span class="string">&quot;AutoLight.cginc&quot;</span></span></span><br><span class="line">            <span class="meta">#<span class="keyword">include</span> <span class="string">&quot;UnityCG.cginc&quot;</span></span></span><br><span class="line"></span><br><span class="line">            <span class="keyword">struct</span> appdata</span><br><span class="line">            &#123;</span><br><span class="line">                float4 vertex : POSITION;</span><br><span class="line">                float2 uv : TEXCOORD0;</span><br><span class="line">                float3 normal:NORMAL;</span><br><span class="line">                float4 tangent:TANGENT;</span><br><span class="line">            &#125;;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">struct</span> <span class="title class_">v2f</span></span><br><span class="line">            &#123;</span><br><span class="line">                float2 texcoord : TEXCOORD0;</span><br><span class="line">                </span><br><span class="line">                float4 pos : SV_POSITION;</span><br><span class="line">                float3 normal_world:TEXCOORD1;</span><br><span class="line">                float3 binormal_world:TEXCOORD2;</span><br><span class="line">                float3 tangent_world:TEXCOORD3;</span><br><span class="line">                float3 pos_world:TEXCOORD4;</span><br><span class="line">                <span class="built_in">LIGHTING_COORDS</span>(<span class="number">5</span>,<span class="number">6</span>)</span><br><span class="line"></span><br><span class="line">            &#125;;</span><br><span class="line"></span><br><span class="line">            sampler2D _Diffuse;</span><br><span class="line">            float4 _Diffuse_ST;</span><br><span class="line">            sampler2D _Normal;</span><br><span class="line">            <span class="type">float</span> _NormalIntensity;</span><br><span class="line">            <span class="type">float</span> _SpecShininess;</span><br><span class="line">            <span class="type">float</span> _Expose;</span><br><span class="line">            float4 _LightColor0;</span><br><span class="line">            float4 _DiffuseColor;</span><br><span class="line">            </span><br><span class="line">            samplerCUBE _EnvMap;</span><br><span class="line">            float4 _EnvMap_HDR;</span><br><span class="line">            <span class="type">float</span> _CurveOffset;</span><br><span class="line">            <span class="type">float</span> _LUTOffset;</span><br><span class="line"></span><br><span class="line">            sampler2D _AnoiseMap;</span><br><span class="line">            float4 _AnoiseMap_ST;</span><br><span class="line">            float4 _SpecularColor1;</span><br><span class="line">            <span class="type">float</span> _SpecShininess1;</span><br><span class="line">            <span class="type">float</span> _Shiftoffset1 ;</span><br><span class="line">            <span class="type">float</span> _SpecNoise1 ;</span><br><span class="line"></span><br><span class="line">            float4 _SpecularColor2;</span><br><span class="line">            <span class="type">float</span> _SpecShininess2;</span><br><span class="line">            <span class="type">float</span> _Shiftoffset2 ;</span><br><span class="line">            <span class="type">float</span> _SpecNoise2 ;</span><br><span class="line">            </span><br><span class="line">             <span class="function">v2f <span class="title">vert</span> <span class="params">(appdata v)</span></span></span><br><span class="line"><span class="function">            </span>&#123;</span><br><span class="line">                v2f o;</span><br><span class="line">                o.pos = <span class="built_in">UnityObjectToClipPos</span>(v.vertex);</span><br><span class="line">                o.texcoord =v.uv;</span><br><span class="line">                o.normal_world = <span class="built_in">normalize</span>(<span class="built_in">mul</span>(<span class="built_in">float4</span>(v.normal,<span class="number">0.0</span>),unity_WorldToObject)).xyz;</span><br><span class="line">                o.tangent_world = <span class="built_in">normalize</span>(<span class="built_in">mul</span>(unity_ObjectToWorld,<span class="built_in">float4</span>(v.tangent.xyz,<span class="number">0.0</span>)));</span><br><span class="line">                o.pos_world = <span class="built_in">normalize</span>(<span class="built_in">mul</span>(unity_ObjectToWorld,<span class="built_in">float4</span>(v.vertex.xyz,<span class="number">0.0</span>)));</span><br><span class="line">                o.binormal_world =<span class="built_in">normalize</span>(<span class="built_in">cross</span>(o.normal_world,o.tangent_world)*v.tangent.w);</span><br><span class="line">                </span><br><span class="line">                <span class="comment">//o.texcoord = TRANSFORM_TEX(v.uv, _MainTex);</span></span><br><span class="line">                <span class="built_in">TRANSFER_VERTEX_TO_FRAGMENT</span>(o);</span><br><span class="line">                <span class="keyword">return</span> o;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="function">fixed4 <span class="title">frag</span> <span class="params">(v2f i)</span> : SV_Target</span></span><br><span class="line"><span class="function">            &#123;</span></span><br><span class="line">            </span><br><span class="line">                </span><br><span class="line">                half atten = <span class="built_in">LIGHT_ATTENUATION</span> (i);</span><br><span class="line">                fixed4 col = <span class="built_in">fixed4</span>(<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>);</span><br><span class="line">                fixed3 albedo = <span class="built_in">tex2D</span>(_Diffuse, i.texcoord).xyz*_DiffuseColor;</span><br><span class="line">                </span><br><span class="line">                fixed3 base_col =albedo ;</span><br><span class="line">                fixed3 spec_color =albedo ;</span><br><span class="line"></span><br><span class="line">                half3 normal_dir    = <span class="built_in">normalize</span>(i.normal_world);</span><br><span class="line">                half3 pos_world    = <span class="built_in">normalize</span>(i.pos_world);</span><br><span class="line">                half3 tangent_dir   = <span class="built_in">normalize</span>(i.tangent_world)*_NormalIntensity;</span><br><span class="line">                half3 binormal_dir  = <span class="built_in">normalize</span>(i.binormal_world)*_NormalIntensity;</span><br><span class="line">                half4 normalmap= <span class="built_in">tex2D</span>(_Normal,i.texcoord);</span><br><span class="line">                half3 normal_data = <span class="built_in">UnpackNormal</span>( normalmap);</span><br><span class="line">                float3x3 TBN = <span class="built_in">float3x3</span>(tangent_dir,binormal_dir,normal_dir);</span><br><span class="line">                normal_dir = <span class="built_in">normalize</span>(<span class="built_in">mul</span>(normal_data,TBN));</span><br><span class="line"></span><br><span class="line">                half3 view_dir = <span class="built_in">normalize</span>(_WorldSpaceCameraPos.xyz-pos_world);</span><br><span class="line">                half3 light_dir = <span class="built_in">normalize</span>(_WorldSpaceLightPos0.xyz);</span><br><span class="line">                </span><br><span class="line">                <span class="comment">//直接光漫反射</span></span><br><span class="line">               </span><br><span class="line">                half diffuse_term = <span class="built_in">max</span>(<span class="built_in">dot</span>(normal_dir,light_dir),<span class="number">0</span>);</span><br><span class="line">                half half_lambert = (diffuse_term+<span class="number">1.0</span>)*<span class="number">0.5</span>;</span><br><span class="line">                half3 comm_diffuse = diffuse_term*base_col*atten*_LightColor0.xyz;</span><br><span class="line">                half3 diffuse = comm_diffuse;</span><br><span class="line">                </span><br><span class="line">                col.xyz+=diffuse;</span><br><span class="line">              <span class="comment">//直接光镜面反射</span></span><br><span class="line">               half roughness = <span class="number">0.2</span>;</span><br><span class="line">               half3 half_dir =<span class="built_in">normalize</span>( light_dir+view_dir);</span><br><span class="line">               half2 uv_Anoise = i.texcoord*_AnoiseMap_ST.xy+_AnoiseMap_ST.zw;</span><br><span class="line">               half3 aniso_noise = <span class="built_in">tex2D</span>(_AnoiseMap,uv_Anoise);</span><br><span class="line"></span><br><span class="line">               half NdotH = <span class="built_in">dot</span>(normal_dir,half_dir);</span><br><span class="line">               half TdotH = <span class="built_in">dot</span>(tangent_dir,half_dir);</span><br><span class="line"></span><br><span class="line">               half NdotV = <span class="built_in">max</span>(<span class="number">0</span>, <span class="built_in">dot</span>(normal_dir,view_dir));</span><br><span class="line">               half aniso_atten = <span class="built_in">saturate</span>(<span class="built_in">sqrt</span>(<span class="built_in">max</span>(<span class="number">0</span>,half_lambert/NdotV)))*atten;</span><br><span class="line">               <span class="comment">//spec1</span></span><br><span class="line">               half3 specular_color1 = _SpecularColor1 + base_col;</span><br><span class="line">               half3 aniso_offset1 = normal_dir *(aniso_noise*_SpecNoise1+_Shiftoffset1);</span><br><span class="line">               half3 binormal_dir1 = <span class="built_in">normalize</span>(binormal_dir + aniso_offset1);</span><br><span class="line">               half BdotH1 = <span class="built_in">dot</span>(binormal_dir1,half_dir)/ _SpecShininess1;</span><br><span class="line">               half3 specular_term1 = <span class="built_in">exp</span>(-(TdotH*TdotH+BdotH1*BdotH1)/(<span class="number">1.0</span>+NdotH));</span><br><span class="line">               half3 specular1 = specular_term1*aniso_atten*specular_color1*_LightColor0.xyz;</span><br><span class="line">               </span><br><span class="line">               half3 specular_color2 = _SpecularColor2 + base_col;</span><br><span class="line">               half3 aniso_offset2 = normal_dir *(aniso_noise*_SpecNoise2+_Shiftoffset2);</span><br><span class="line">               half3 binormal_dir2 = <span class="built_in">normalize</span>(binormal_dir + aniso_offset2);</span><br><span class="line">               half BdotH2 = <span class="built_in">dot</span>(binormal_dir2,half_dir)/ _SpecShininess2;</span><br><span class="line">               half3 specular_term2 = <span class="built_in">exp</span>(-(TdotH*TdotH+BdotH2*BdotH2)/(<span class="number">1.0</span>+NdotH));</span><br><span class="line">               half3 specular2 = specular_term2*aniso_atten*specular_color2*_LightColor0.xyz;</span><br><span class="line">               half3 specular = specular1+specular2;</span><br><span class="line">               col.xyz+=specular;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">                <span class="comment">//间接镜面反射</span></span><br><span class="line">               roughness=roughness*(<span class="number">1.7</span><span class="number">-0.7</span>*roughness);</span><br><span class="line">               half mip_level = roughness*<span class="number">6.0</span>;</span><br><span class="line">               half4 Cube_col=<span class="built_in">texCUBElod</span>(_EnvMap,<span class="built_in">float4</span>(half_dir,mip_level));</span><br><span class="line">               half3 EnvHDR_col=<span class="built_in">DecodeHDR</span>(Cube_col,_EnvMap_HDR);</span><br><span class="line">               half3 env_specular = EnvHDR_col *spec_color*half_lambert*_Expose;</span><br><span class="line">               col.xyz+=env_specular;</span><br><span class="line">               <span class="comment">//return col;</span></span><br><span class="line">               <span class="keyword">return</span> <span class="built_in">fixed4</span>(specular,<span class="number">1.0</span>);</span><br><span class="line">            &#125;</span><br><span class="line">            ENDCG</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    FallBack <span class="string">&quot;Diffuse&quot;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>




            <!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->
            <audio id="audio" loop="1" preload="auto" controls="controls" data-autoplay="false">
                <source type="audio/mpeg" src="/music/jucilang.mp3">
            </audio>
            
        </div>
        
    <div id='gitalk-container' class="comment link"
		data-enable='true'
        data-ae='true'
        data-ci='99f95a936c6fcdb1bd67'
        data-cs='c2d1bba3d6b7f9ade4f3de09a63925bd837c25ea'
        data-r='mrchenlearnspace.github.io'
        data-o='MrChenLearnSpace'
        data-a='MrChenLearnSpace'
        data-d='false'
    >查看评论</div>


    </div>
    
        <div class='side'>
			<ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%A8%A1%E5%9E%8B%E4%B8%8E%E8%B4%B4%E5%9B%BE%E5%88%86%E6%9E%90"><span class="toc-number">1.</span> <span class="toc-text">模型与贴图分析</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A8%A1%E5%9E%8B"><span class="toc-number">1.1.</span> <span class="toc-text">模型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%B4%B4%E5%9B%BE%E5%88%86%E6%9E%90"><span class="toc-number">1.2.</span> <span class="toc-text">贴图分析</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Albedo-%E8%B4%B4%E5%9B%BE"><span class="toc-number">1.2.1.</span> <span class="toc-text">Albedo 贴图</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#combmap-%E8%B4%B4%E5%9B%BE"><span class="toc-number">1.2.2.</span> <span class="toc-text">combmap 贴图</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B3%95%E7%BA%BF%E8%B4%B4%E5%9B%BE"><span class="toc-number">1.2.3.</span> <span class="toc-text">法线贴图</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%85%89%E7%85%A7%E6%A1%86%E6%9E%B6"><span class="toc-number">2.</span> <span class="toc-text">光照框架</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9B%B4%E6%8E%A5%E5%85%89%E7%85%A7%E5%8F%8D%E5%B0%84"><span class="toc-number">2.1.</span> <span class="toc-text">直接光照反射</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#lambert"><span class="toc-number">2.1.1.</span> <span class="toc-text">lambert</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#SSS-%E6%95%A3%E5%85%89"><span class="toc-number">2.1.2.</span> <span class="toc-text">SSS 散光</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9B%B4%E6%8E%A5%E5%85%89%E9%95%9C%E9%9D%A2%E5%8F%8D%E5%B0%84"><span class="toc-number">2.2.</span> <span class="toc-text">直接光镜面反射</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Blin-Phong"><span class="toc-number">2.2.1.</span> <span class="toc-text">Blin-Phong</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#KK%E5%90%84%E9%A1%B9%E5%BC%82%E6%80%A7"><span class="toc-number">2.2.2.</span> <span class="toc-text">KK各项异性</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#ACES-Tonemapping"><span class="toc-number">3.</span> <span class="toc-text">ACES_Tonemapping</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%AE%8F%E5%BC%80%E5%85%B3"><span class="toc-number">4.</span> <span class="toc-text">宏开关</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%BA%E7%89%A9%E4%BB%A3%E7%A0%81"><span class="toc-number">5.</span> <span class="toc-text">人物代码</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%A4%B4%E5%8F%91%E4%BB%A3%E7%A0%81"><span class="toc-number">6.</span> <span class="toc-text">头发代码</span></a></li></ol>	
        </div>
    
</div>


    </div>
</div>
</body>

<script src="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>


<script src="//lib.baomitu.com/jquery/1.8.3/jquery.min.js"></script>
<script src="/blog/js/plugin.js"></script>
<script src="/blog/js/typed.js"></script>
<script src="/blog/js/diaspora.js"></script>


<link rel="stylesheet" href="/blog/photoswipe/photoswipe.css">
<link rel="stylesheet" href="/blog/photoswipe/default-skin/default-skin.css">


<script src="/blog/photoswipe/photoswipe.min.js"></script>
<script src="/blog/photoswipe/photoswipe-ui-default.min.js"></script>


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>
    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">
        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>
        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">
            <div class="pswp__top-bar">
                <!--  Controls are self-explanatory. Order can be changed. -->
                <div class="pswp__counter"></div>
                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
                <button class="pswp__button pswp__button--share" title="Share"></button>
                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                      <div class="pswp__preloader__cut">
                        <div class="pswp__preloader__donut"></div>
                      </div>
                    </div>
                </div>
            </div>
            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div> 
            </div>
            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>
            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>
            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>
        </div>
    </div>
</div>



<script type="text/x-mathjax-config">
    MathJax.Hub.Config({"HTML-CSS": { preferredFont: "TeX", availableFonts: ["STIX","TeX"], linebreaks: { automatic:true }, EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50) },
        tex2jax: { inlineMath: [ ["$", "$"], ["\\(","\\)"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno",skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']},
        TeX: {  noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } }, Macros: { href: "{}" } },
        messageStyle: "none"
    });
</script>
<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>



<!-- Google Analytics -->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-YMJ8CBH8F7"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-YMJ8CBH8F7');
</script>
<!-- End Google Analytics -->


</html>
